package com.ruoyi.web.controller.bookkeeping;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.bookkeeping.domain.param.AddBookNoticeParam;
import com.ruoyi.bookkeeping.domain.param.PageQueryParam;
import com.ruoyi.bookkeeping.domain.param.UpdateBookNoticeParam;
import com.ruoyi.bookkeeping.domain.vo.BookBeNoticeVo;
import com.ruoyi.bookkeeping.domain.vo.MsgResult;
import com.ruoyi.bookkeeping.domain.vo.TableDataInfoVo;
import com.ruoyi.bookkeeping.util.GetPageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookkeeping.service.IBookNoticeService;

import java.util.List;

/**
 * 好友请求Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/bookkeeping/notice")
@Api(tags = "好友模块")
public class BookNoticeController extends BaseController
{
    @Autowired
    private IBookNoticeService bookNoticeService;

    /**
     * 查询被好友请求列表
     */
    @GetMapping("/list")
    @ApiOperation("查询被好友请求列表")
    public TableDataInfoVo<List<BookBeNoticeVo>> list(PageQueryParam pageQuery)
    {
        Page page = GetPageUtil.getPages(pageQuery.getPageNum(),pageQuery.getPageSize(),bookNoticeService.selectBookNoticeList(getUserId()));
        return getDataTable(page.getRecords(),page.getTotal());
    }

    /**
     * 新增好友请求
     */
    @Log(title = "好友请求", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加好友")
    public MsgResult add(@RequestBody AddBookNoticeParam addBookNoticeParam)
    {
        int i = bookNoticeService.insertBookNotice(addBookNoticeParam, getUserId());
        if(i == 0){
            return success("该用户已经是你的好友，请勿重复添加");
        }else if(i == 2){
            return success("不能添加自己为好友噢");
        }
        return success("发送成功");
    }

    /**
     * 修改好友请求
     */
    @Log(title = "好友请求", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("处理好友请求")
    public MsgResult edit(@RequestBody UpdateBookNoticeParam updateBookNoticeParam)
    {
        return toAjax(bookNoticeService.updateBookNotice(updateBookNoticeParam,getUserId()));
    }

}
